package j_util.data_structures.stack;

import j_util.KeyboardInput;
import j_util.Utiles;
/*

    This file is part of Logica-Logike.

    Logica-Logike is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation version 3 of the License.

    Logica-Logike is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with Logica-Logike.  If not, see <http://www.gnu.org/licenses/>.

 */
/**
 * This tests a StackInterface;
 *
 * @author Jose Martin Rozanec;
 */
public class TestStack {

    public static int cantElementos(StackInterface p) {
        int cont = 0;
        StackInterface aux = new StackE();
        while (!p.isEmpty()) {
            aux.push(p.top());
            p.pop();
            cont++;
        }
        while (!aux.isEmpty()) {
            p.push(aux.top());
            aux.pop();
        }
        return cont;
    }

    public static void main(String[] args) {

        String menu[] = new String[6];
        menu[0] = "1- Agregar elemento a la stack.";
        menu[1] = "2- Sacar elemento de la stack.";
        menu[2] = "3- Ver ultimo elemento de la stack";
        menu[3] = "4- Ver si la stack se halla vacia";
        menu[4] = "5- Ver tamaño de la stack";
        menu[5] = "6- Salir";

        int k;
        StackInterface p = new StackE();
        int option;
        do {
            option = Utiles.menu("Menu StackInterface", menu);
            switch (option) {
                case 1:
                    k = KeyboardInput.integerValue("Ingrese un integerValue.");
                    while (k != 0) {
                        p.push(new Integer(k));
                        k = KeyboardInput.integerValue("Ingrese un integerValue.");
                    }
                    break;
                case 2:
                    p.pop();
                    break;
                case 3:
                    System.out.println("El ultimo elemento apilado es: " + p.top());
                    break;
                case 4:
                    if (p.isEmpty()) {
                        System.out.println("La stack se halla vacia.");
                    } else {
                        System.out.println("La stack no se halla vacia.");
                    }
                    break;
                case 5:
                    System.out.println("La stack posee " + cantElementos(p) + " elementos.");
                    break;
                case 6:
                    System.exit(6);
            }
        } while (option != 6);
    }
}

